package com.itheima.d3_stream;

import java.util.*;
import java.util.stream.Collectors;
import java.util.stream.IntStream;
import java.util.stream.Stream;

/*
        目标：掌握Stream流的创建。

        1 单列集合获取Stream流
        2 双列集合获取Stream流
        3 数组获取Stream流
        4 同一种类型多个数据获取Stream流
 */
public class StreamTest2 {
    public static void main(String[] args) {
        // 1、如何获取List集合的Stream流？
        List<String> names = new ArrayList<>();
        Collections.addAll(names, "张三丰", "张无忌", "周芷若", "赵敏", "张强");
        names.stream().filter((name) -> {
            return name.startsWith("张");
        }).forEach((s -> System.out.println(s)));

// 2 双列集合获取Stream流
        Map<String, String> map = new HashMap<>();
        map.put("001", "张东");
        map.put("002", "李强");
        map.put("003", "王国栋");
        map.put("004", "张晓丽");
        Stream<Map.Entry<String, String>> entryStream = map.entrySet().stream().filter((entry -> {
            return entry.getKey().startsWith("张");
        }));
        // 3 数组获取Stream流
        int arr[] = {1, 2, 3, 44, 55, 66};
        Arrays.stream(arr).filter(a->a>=10).forEach(s-> System.out.println(s));
        // 4 同一种类型多个数据获取Stream流
        Stream<String> stringStream = Stream.of("你好", "hello", "world", "love");
        stringStream.forEach(s -> System.out.println(s));


    }
}
